home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / redo / redoFileKeyInsert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.1 KB  |  203 lines

  1. /*
  2.  *   $RCSfile: redoFileKeyInsert.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:57 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "log.h"
  57. #include "pool.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "trans.h"
  61. #include "bitmap.h"
  62. #include "file.h"
  63. #include "openlog.h"
  64. #include "bf_extfuncs.h"
  65. #include "bm_extfuncs.h"
  66. #include "fi_intfuncs.h"
  67. #include "trans_extfuncs.h"
  68. #include "redo_extfuncs.h"
  69. #include "logaction.h"
  70. #include "util_funcs.h"
  71. #include "thread_globals.h"
  72. #include "bf_globals.h"
  73. #include "log_globals.h"
  74. #include "log_extfuncs.h"
  75.  
  76.  
  77.  void
  78. redoFileKeyInsert (
  79.  
  80.     LOGRECORDHDR        *record 
  81. )
  82. {
  83.  
  84.     register PID        *pid;
  85.     register FOUR        *insertLoc;
  86.     register SHORTPID    *key;
  87.     register NODEPAGE    *nodePage;
  88.     register GROUPLINK    *nodeLink;
  89.     register BOOL        *large;
  90.     DIRTYPAGEINFO        *dirtyInfo;
  91.  
  92.  
  93.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN.offset));
  94.  
  95.     /*
  96.      *    get a pointer to the name in the record
  97.      */
  98.     pid = &(record->actionPid);
  99.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  100.  
  101.     /*
  102.      *    get a pointer to the name in the record
  103.      */
  104.     insertLoc = (FOUR *) GET_LOG_IMAGE(record, 0);
  105.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("insertLoc:%d", *insertLoc));
  106.  
  107.     /*
  108.      *    get a pointer to the name in the record
  109.      */
  110.     key = (SHORTPID *) GET_LOG_IMAGE(record, 1);
  111.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("key:%d", *key));
  112.  
  113.     /*
  114.      *    get a pointer to the large flag
  115.      */
  116.     large = (BOOL *) GET_LOG_IMAGE(record, 2);
  117.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("large:%d", *large));
  118.  
  119.     /*
  120.      *    check to see if the page is in the dirty page list
  121.      */
  122.     if ((dirtyInfo = searchDirtyPageTable(pid)) == NULL)    {
  123.  
  124.         /*
  125.          *    don't need to redo
  126.          */
  127.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  128.         return;
  129.     }
  130.  
  131.     /*
  132.      *  check to see if the lrc on the page is greater than
  133.      *  the lrc in the log record.
  134.      *  Also check the lsn for the case of pages which never made it
  135.      *  back from the client.
  136.      */
  137.     if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
  138.  
  139.         /*
  140.          *  don't need to redo
  141.          */
  142.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  143.         return;
  144.     }
  145.  
  146.     /*
  147.      * Read in first page of file and grab node type
  148.      */
  149.     if ((nodeLink = bf_ReadPage(UserBufGroup, pid, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
  150.  
  151.         SM_ERROR(TYPE_FATAL, Active->errno);
  152.     }
  153.  
  154.     /*
  155.      *    get a pointer to the node page
  156.      */
  157.     nodePage = (NODEPAGE *) nodeLink->bufFrame;
  158.  
  159.     /*
  160.      *    check to see if the lrc on the page is greater than
  161.      *    the lrc in the log record
  162.      */
  163.     if (compareLRC( &(record->actionLRC), &(nodePage->header.lrc)) <= 0)    {
  164.  
  165.         /*
  166.          *    don't need to redo
  167.          *    mark the page lrc
  168.          */
  169.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  170.         dirtyInfo->lrc = nodePage->header.lrc;
  171.  
  172.         /*
  173.          *    release the page
  174.          */
  175.         signalSemaphore( &(nodeLink->pageHash->semaphore) );
  176.         bf_UnfixPage(nodeLink, BF_DEFAULT, FALSE);
  177.         return;
  178.     }
  179.  
  180.     /*
  181.      *    insert the key
  182.      */
  183.     FI_InsertToArray(nodePage, *insertLoc, *key, NULLPID, *large);
  184.  
  185.     /*
  186.      *    mark the LRC on the page
  187.      *    Set up the firstLSN/LRC for the page
  188.      */
  189.     nodePage->header.lrc = record->actionLRC;
  190.     DEPEND_LOG(nodeLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  191.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", nodePage->header.lrc.count));
  192.  
  193.     /*
  194.      *    release  the page semaphore
  195.      */
  196.     signalSemaphore( &(nodeLink->pageHash->semaphore) );
  197.  
  198.     /*
  199.      *    release and dirty the page
  200.      */
  201.     bf_UnfixPage(nodeLink, BF_DEFAULT, TRUE);
  202. }
  203.